IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FUBGetLastDayMonth]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
BEGIN
	DROP FUNCTION [dbo].[FUBGetLastDayMonth]
END
GO


CREATE FUNCTION FUBGetLastDayMonth (@pYear NUMERIC (4,0), @pMonth NUMERIC (2,0))
RETURNS NUMERIC (2,0)
AS
BEGIN

	DECLARE @date AS DATETIME
	
	
	SET @date = dbo.FUBGetDateFromParts (@pYear, @pMonth, 1);

    RETURN 
		DATEPART (d, DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@date)+1,0)))

END
GO